package com.wanmait.baohan.controller.purchaseController;

import com.github.pagehelper.PageInfo;
import com.wanmait.baohan.pojo.InitiateProject;
import com.wanmait.baohan.service.DictionaryService;
import com.wanmait.baohan.service.InitiateProjectService;
import com.wanmait.baohan.service.SuppilerService;
import com.wanmait.baohan.vo.DataVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/purchase")
public class InitiatePurchaseProjectController {
    @Resource
    private InitiateProjectService initiateProjectService;
    @Resource
    private DictionaryService dictionaryService;
    @Resource
    private SuppilerService suppilerService;

    //高文强  发起一个采购项目
    @RequestMapping("approveInitiatePurchaseProject")
    public String initiatePurchaseProject( )
    {
        return "purchase/approveInitiatePurchaseProject";
    }

    /**
     * hxn
     * @param initiateProject
     * @return
     * 上传立项信息
     */
    @RequestMapping("uploadInitiateProject")
    @ResponseBody
    public String uploadInitiateProject(@RequestBody InitiateProject initiateProject){
        try {
            initiateProjectService.uploadInitiateProject(initiateProject);
            return "0";
        }catch (Exception e){
            return "1";
        }
    }
    /**
     * 打开立项列表
     */
    @RequestMapping("/procurementList")
    public void procurementList() {

    }
    //高文强  提交发起的申请
    @RequestMapping("submissionMode")
    @ResponseBody
    public void submissionMode(Integer procurementModel, Integer product, Integer suppiler, HttpServletRequest request)
    {


    }

    /**
     * hxn
     * @param limit
     * @param page
     * @param enable
     * @return
     *
     */
    @ResponseBody
    @RequestMapping("/tableList")
    public DataVo<InitiateProject> tableList(Integer limit, Integer page, Integer enable){
        DataVo dataVo =new DataVo();
        PageInfo<InitiateProject> list =  initiateProjectService.findList(page, limit,enable);
        dataVo.setCount(list.getTotal());
        dataVo.setData(list.getList());
        return dataVo;
    }


    @ResponseBody
    @RequestMapping("getAllInitiateProjectByWorkTemplateId")
    public List<InitiateProject> getAllInitiateProjectByWorkTemplateId(Integer id){
        return initiateProjectService.getAllInitiateProjectByWorkTemplateId(id);
    }
}
